{$CLEO .qa}
{$USE CLEO+}
{$USE Audio}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "StArtQ"

// By ArtemQa146

const
    Stand = 31@
    Stand_2 = 30@
    Stand_3 = 29@
    Stand_4 = 28@
    Ped_Stand = 27@
    
    coords_x = 26@
    coords_y = 25@
    coords_z = 24@
    angle_1 = 23@
    Audio_draw = 21@
    location_check = 20@
    render_brush = 19@
    render_stand = 18@
    Radius_in = 120.0
end

0087: coords_x = 0@ // (float)
0087: coords_y = 1@ // (float)
0087: coords_z = 2@ // (float)
0087: angle_1 = 3@ // (float)
0085: location_check = 4@ // (int)
0085: render_brush = 5@ // (int)
0085: render_stand = 6@ // (int)

if
    0E4D: random_percent 75
then
else
    repeat
    wait 0
    until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 150.0
    0A93: terminate_this_custom_script
end

            repeat
            wait 0
            04ED: load_animation  "PedEventsMod"
            until 04EE:   animation "PedEventsMod" loaded

            model.Load(1416)
            model.Load(188)
            model.Load(3014)
            if
                not model.Available(1416)
            then
                repeat
                wait 0
                model.Load(1416)
                until model.Available(1416)
            end
            if
                not model.Available(188)
            then
                repeat
                wait 0
                model.Load(188)
                until model.Available(188)
            end
            if
                not model.Available(3014)
            then
                repeat
                wait 0
                model.Load(3014)
                until model.Available(3014)
            end
            038B: load_requested_models

            009A: Ped_Stand = create_actor_pedtype 21 model 188 at coords_x coords_y coords_z
            0173: set_actor Ped_Stand Z_angle_to angle_1
            0E24: fix_char Ped_Stand ground 1 brightness 1 and_fade_in 0
            0F02: create_render_object_to_char_bone_from_special Ped_Stand special_model render_brush bone 24 offset 0 0 0 rotation 0 0 0 store_to 1@

            // 
            04C4: store_coords_to 1@ 2@ 3@ from_actor Ped_Stand with_offset 0.0 1.3 0.0
            create_object_no_save 1416 at 1@ 2@ 3@ offset 0 ground 0 to Stand_4
            create_object_no_save 1416 at 1@ 2@ 3@ offset 0 ground 0 to Stand
            0172: 1@ = actor Ped_Stand Z_angle
            0177: set_object Stand_4 Z_angle_to 1@
            08D2: object Stand_4 scale_model 0.0
            0177: set_object Stand Z_angle_to 1@
            08D2: object Stand scale_model 0.0
            
            if location_check == 1
            then 0AF0: 1@ = read_int_from_ini_file "cleo\Busy Workers.ini" section "models" key "Stand_1"
            end
            if location_check == 2
            then 0AF0: 1@ = read_int_from_ini_file "cleo\Busy Workers.ini" section "models" key "Stand_2"
            end
            if location_check == 3
            then 0AF0: 1@ = read_int_from_ini_file "cleo\Busy Workers.ini" section "models" key "Stand_3"
            end
            0F04: create_render_object_to_object_from_special Stand_4 special_model 1@ offset 0.1 0 0.0 rotation 0 0 0 store_to 2@
            0F04: create_render_object_to_object_from_special Stand special_model 1@ offset 0.1 0 0.0 rotation 0 0 0 store_to 2@

            // 2    
            04C4: store_coords_to 1@ 2@ 3@ from_actor Ped_Stand with_offset -1.0 0.6 0.0
            create_object_no_save 3014 at 1@ 2@ 3@ offset 0 ground 0 to Stand_2
            create_object_no_save 3014 at 1@ 2@ 3@ offset 0 ground 0 to Stand_3
            0172: 1@ = actor Ped_Stand Z_angle
            1@ += 90.0
            0177: set_object Stand_2 Z_angle_to 1@
            08D2: object Stand_2 scale_model 0.0
            0177: set_object Stand_3 Z_angle_to 1@
            08D2: object Stand_3 scale_model 0.0
            07F7: set_object Stand_3 destructible 0
            07F7: set_object Stand_2 destructible 0
            0F04: create_render_object_to_object_from_special Stand_2 special_model render_stand offset 0.0 0.0 -1.0 rotation 0 0 270.0 store_to 2@
            0E37: set_render_object_scale 2@ 0.9 0.9 0.9
            0F04: create_render_object_to_object_from_special Stand_3 special_model render_stand offset 0.0 0.0 -1.0 rotation 0 0 270.0 store_to 2@
            0E37: set_render_object_scale 2@ 0.9 0.9 0.9

            model.Destroy(188)
            model.Destroy(1416)
            model.Destroy(3014)

            0812: AS_actor Ped_Stand perform_animation "Draw" IFP "PedEventsMod" framedelta 1.0 loopA 1 lockX 0 lockY 0 lockF 1 time -1  // versionB

            0AC1: Audio_draw = load_audio_stream_with_3d_support "SQ\Draw1.mp3" // IF and SET
            0AC4: link_3d_audio_stream Audio_draw to_actor Ped_Stand
            0AAD: set_audio_stream Audio_draw state 1
            0AC0: audio_stream Audio_draw looped 1
            0ABC: set_audio_stream Audio_draw volume 0.6

            wait 300

            repeat
            wait 0
            gosub @Check //  , 
            if
                1@ == true
            then
                if
                    not locate_char_distance_to_coordinates $player_actor pos coords_x coords_y coords_z radius Radius_in
                then
                    break
                end

            else
                break
            end
            until not player.Defined(0)
            04EF: release_animation "PedEventsMod"
            if not Audio_draw == -1
            then 0AAE: remove_audio_stream Audio_draw
            end
            if
                0EEA: locate_char_distance_to_coordinates $player_actor pos coords_x coords_y coords_z radius Radius_in
            then
                if 03CA:   object Stand exists
                then 01C4: remove_references_to_object Stand // This object will now disappear when the player looks away
                end
                if 03CA:   object Stand_2 exists
                then 01C4: remove_references_to_object Stand_2 // This object will now disappear when the player looks away
                end
                if 03CA:   object Stand_4 exists
                then 01C4: remove_references_to_object Stand_4 // This object will now disappear when the player looks away
                end
                if 03CA:   object Stand_3 exists
                then 01C4: remove_references_to_object Stand_3 // This object will now disappear when the player looks away
                end
                if 056D:   actor Ped_Stand defined
                then 01C2: remove_references_to_actor Ped_Stand // Like turning an actor into a random pedestrian
                end
            else
                if 03CA:   object Stand exists
                then object.Destroy(Stand)
                end
                if 03CA:   object Stand_2 exists
                then object.Destroy(Stand_2)
                end
                if 03CA:   object Stand_4 exists
                then object.Destroy(Stand_4)
                end
                if 03CA:   object Stand_3 exists
                then object.Destroy(Stand_3)
                end
                if 056D:   actor Ped_Stand defined
                then 009B: destroy_actor Ped_Stand
                end
            end
0A93: terminate_this_custom_script


:Check
1@ = false
if and
    056D:   actor Ped_Stand defined
    03CA:   object Stand_4 exists
    03CA:   object Stand_3 exists
    03CA:   object Stand exists
    03CA:   object Stand_2 exists
then
    1@ = true

    // , ,    
    080E: get_actor $PLAYER_ACTOR ped_event_to 2@
    080E: get_actor Ped_Stand ped_event_to 3@
    if or
        actor.Dead(Ped_Stand)
        2@ == 11
        3@ == 49
        3@ == 9
        051A:   actor Ped_Stand damaged_by_actor $PLAYER_ACTOR
        not is_char_script_controlled Ped_Stand
        not $ACTIVE_INTERIOR == 0
    then
        1@ = false
    end
    
    080E: get_actor Ped_Stand ped_event_to 2@
    if or
        2@ == 15
        2@ == 31
        2@ == 59
    then
        1@ = false
    end
    
    if
        8611:   not actor Ped_Stand performing_animation "Draw"
    then
        1@ = false
    end



    //    
    if
        0457:   player $PLAYER_CHAR aiming_at_actor Ped_Stand
    then
        0E83: get_current_char_weaponinfo $PLAYER_ACTOR store_to 3@
        0E89: get_weaponinfo_fire_type 3@ store_to 2@ //     
        if or
            2@ == 1 //  
            2@ == 3 //   (  ..)
        then
            1@ = false
        end
    end

    //   
    0D59: get_current_weather_to 2@
    0E40: get_current_hour 3@
    if or
        not 3@ >= 9
        not 18 > 3@
        2@ == 8
        2@ == 16
    then
        1@ = false
    end

else
    1@ = false
end
return


